component extends="Controller" output="false" {
  
  public void function init(){
  }
  
  // fixtures/index
  public void function index(){
    fixtures = model("Fixture").findAll();
  }
  
  // fixtures/show/key
  public void function show(){
    fixture = model("Fixture").findByKey(params.key);
    	
    if (!IsObject(fixture)){
      flashInsert(error="Fixture #params.key# was not found");
      redirectTo(action="index");
    }
  }
  
  // fixtures/new
  public void function new(){
    clubs = model("Club").findAll();
    fixture = model("Fixture").new();
  }
  
  //fixtures/edit/key
  public void function edit(){
    clubs = model("Club").findAll();
    fixture = model("Fixture").findByKey(params.key);
    	
    if (!IsObject(fixture)){
	    flashInsert(error="Fixture #params.key# was not found");
			redirectTo(action="index");
	  }
  }
  
  // fixtures/create
  public void function create(){
    fixture = model("Fixture").new(params.fixture);
		
		if (fixture.save()){
			flashInsert(success="The fixture was created successfully.");
      redirectTo(action="index");
		} else {
		  flashInsert(error="There was an error creating the fixture.");
		  renderPage(action="new");
		}
  }
  
  // fixtures/update
  public void function update(){
    fixture = model("Fixture").findByKey(params.key);
		
		if (fixture.update(params.fixture)){
		  flashInsert(success="The fixture was updated successfully.");
      redirectTo(action="index");
		} else {
		  flashInsert(error="There was an error updating the fixture.");
			renderPage(action="edit");
		}
  }
  
  // fixtures/delete/key
  public void function delete(){
    fixture = model("Fixture").findByKey(params.key);

		if (fixture.delete()){
			flashInsert(success="The fixture was deleted successfully.");
      redirectTo(action="index");
    } else {
      flashInsert(error="There was an error deleting the fixture.");
			redirectTo(action="index");
    }
  }
  
}
